//
//  SearchConditionViewController.m
//  YJRenter
//
//  Created by 文彬 on 2018/7/13.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "SearchConditionViewController.h"
#import "MessItemTableViewCell.h"
#import "SearchTimeTableViewCell.h"
#import "HXTagsView.h"
#import "HXTagAttribute.h"
#import "SearchTypeFirlterView.h"

@interface SearchConditionViewController ()<UITableViewDelegate,
    UITableViewDataSource>

@property (strong, nonatomic) UITableView *listTableView;

@end

@implementation SearchConditionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"意居搜索";
    [self initPageControl];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark 页面相关
- (void)initPageControl{

    [self.view addSubview:self.listTableView];
    [self.listTableView makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.right.equalTo(@0);
    }];
    
    [self addTableFoot];
}

- (void)addTableFoot{
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 400)];
    self.listTableView.tableFooterView = footView;
    
    UIButton *resetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [resetBtn setTitle:@"重设" forState:UIControlStateNormal];
    [resetBtn setTitleColor:kTitleColor forState:UIControlStateNormal];
    resetBtn.layer.borderColor = kMainOriginColor.CGColor;
    resetBtn.layer.borderWidth = 0.5;
    resetBtn.layer.cornerRadius = 4;
    resetBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [footView addSubview:resetBtn];
    [resetBtn makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@100);
        make.height.equalTo(@50);
        make.right.equalTo(footView.centerX).offset(-20);
        make.top.equalTo(@30);
    }];
    
    UIButton *okBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [okBtn setTitle:@"确认" forState:UIControlStateNormal];
    [okBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    okBtn.backgroundColor = kMainOriginColor;
    okBtn.layer.cornerRadius = 4;
    okBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [footView addSubview:okBtn];
    [okBtn makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@100);
        make.height.equalTo(@50);
        make.left.equalTo(footView.centerX).offset(20);
        make.centerY.equalTo(resetBtn.centerY);
    }];
    
    UILabel *messLabel = [[UILabel alloc]init];
    messLabel.text = @"历史搜索";
    messLabel.font = [UIFont systemFontOfSize:15];
    [footView addSubview:messLabel];
    [messLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(resetBtn.bottom).offset(30);
        make.height.equalTo(@20);
        make.width.equalTo(@100);
    }];
    
    HXTagAttribute *atribute = [[HXTagAttribute alloc]init];
    atribute.borderWidth = 0.5;
    atribute.borderColor = kSecTitleColor;
    atribute.normalBackgroundColor = [UIColor whiteColor];
    atribute.selectedBackgroundColor = [UIColor whiteColor];
    atribute.textColor = kTitleColor;
    atribute.selectTextColor = kTitleColor;
    atribute.tagSpace = 20;
    atribute.titleSize = 14;
    
    HXTagsView *tagsView = [[HXTagsView alloc] init];
    tagsView.backgroundColor = [UIColor clearColor];
    tagsView.tagAttribute = atribute;
    tagsView.isMultiSelect = NO;
    tagsView.layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    tagsView.tags = @[@"三亚",@"海口",@"呼伦贝尔",@"西藏",@"广西壮族自治区",@"三亚",@"海口",@"呼伦贝尔",@"西藏",@"广西壮族自治区",@"三亚",@"海口",@"呼伦贝尔",@"西藏",@"广西壮族自治区",@"三亚",@"海口",@"呼伦贝尔",@"西藏",@"广西壮族自治区"];
    tagsView.completion = ^(NSArray *selectTags,NSInteger currentIndex) {
        
    };
 
    [footView addSubview:tagsView];
    [tagsView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(messLabel.bottom).offset(10);
        make.bottom.equalTo(@0);
    }];
}

#pragma mark UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==2) {
        
        SearchTimeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SearchTimeTableViewCell" forIndexPath:indexPath];
        return cell;
    }
    MessItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MessItemTableViewCell" forIndexPath:indexPath];
    cell.titleLabel.adjustsFontSizeToFitWidth = YES;
    [cell showDetailLabe:NO];
    if(indexPath.row==0){
        cell.titleLabel.text = @"三亚";
    }
    else if(indexPath.row==1){
        cell.titleLabel.text = @"短租";
    }
    else if(indexPath.row==3){
        cell.titleLabel.text = @"三亚湾";
    }
    else if(indexPath.row==4){
        cell.titleLabel.text = @"6人，3居，￥100-￥600";
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==1) {
        SearchTypeFirlterView *firlterView = [[SearchTypeFirlterView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        [self.view.window addSubview:firlterView];
    }
}
#pragma mark getter
- (UITableView*)listTableView{
    if (_listTableView==nil) {
        _listTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _listTableView.delegate = self;
        _listTableView.dataSource = self;
        _listTableView.sectionFooterHeight = 0;
        _listTableView.separatorColor = kLineColor;
        _listTableView.backgroundColor = [UIColor clearColor];
        [_listTableView registerNib:[UINib nibWithNibName:@"MessItemTableViewCell" bundle:nil] forCellReuseIdentifier:@"MessItemTableViewCell"];
        [_listTableView registerNib:[UINib nibWithNibName:@"SearchTimeTableViewCell" bundle:nil] forCellReuseIdentifier:@"SearchTimeTableViewCell"];
        
    }
    
    return _listTableView;
}

@end
